package org.apache.sad.core.framework.utils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * This class configures all the fields we need to obfuscate when
 * we are logging and auditing xml/soap soap and request, as well
 * as java instances.
 * 
 * The configuration is used by ToStringBuilder, DebugHandler and 
 * TransactionAuditingAspect.
 * 
 * This class will be defined as Spring bean with the configuration. 
 * 
 * NOTES: The ObfuscationConfiguration bean can be defined multiple
 * times with different bean names, and obfuscatedFields configuration
 * will be merged. This is to allow connector components to define 
 * its own ofuscation configurations in its spring configuration file.
 * 
 * For example:
 * 
 * 	<bean name="ObfuscationConfiguraton" class="com.comcast.core.framework.util.ObfuscationConfiguration">
 *		<!-- Configures comma delimited field list that need to be obfuscated across the board.  -->
 *		<property name="obfuscatedFields" value="${obfuscated.fields}"/>
 * 	</bean>
 */
public class ObfuscationConfiguration {
	private static Set<String> obfuscatedFields = new HashSet<String>();
	
	public void setObfuscatedFields(String[] obfuscatedFields) {
		addObfuscatedFields(obfuscatedFields);
	}
	
	public static synchronized void addObfuscatedFields(String[] obfuscatedFields) {
		ObfuscationConfiguration.obfuscatedFields.addAll(Arrays.asList(obfuscatedFields));
	}
	
	public static Set<String> getObfuscatedFields() {
		return obfuscatedFields;
	}

	public static String[] getObfuscatedFieldsAsArray() {
		return obfuscatedFields.toArray(new String[obfuscatedFields.size()]);
	}
}
